<?php
/* @var $this yii\web\View */
/* @var $model \fztadmin\modules\rbac\models\forms\UserInvite */

use kartik\form\ActiveForm;
use yii\bootstrap\Html;
use wodrow\yii2wtools\tools\JsBlock;
use yii\helpers\Url;
use common\Tools;
use common\assets\Layui;

if (!Yii::$app->request->isAjax) {
    $layui = Layui::register($this);
}
$registerUrl = \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['custom/default/fzt-user-register', 'code' => $model->code]);
?>
    <div class="user-created">
        <div>
            创建邀请链接成功，链接地址：
            <span class="toCopy"><?=$registerUrl ?></span>
            <?=Html::button("复制", ['class' => "btn btn-info btn-xs btn-toCopy", 'id' => "btn-toCopy"]) ?>
        </div>
        <div class="text-warning">链接24小时有效，仅能使用一次，若按钮无法复制请手动复制</div>
    </div>

<?php JsBlock::begin(); ?>
<?php if(!Yii::$app->request->isAjax): ?>
    <script>
        function copyText(text) {
            var oInput = document.createElement('input');
            oInput.value = text;
            document.body.appendChild(oInput);
            oInput.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            oInput.className = 'oInput';
            oInput.style.display='none';
            layui.use('layer', function(){
                layer.msg('复制成功')
            });
        }
        $("#btn-toCopy").click(function () {
            var url = "<?=$registerUrl ?>";
            copyText(url);
        });
        $(document).ready(function () {});
    </script>
<?php endif; ?>
<?php JsBlock::end(); ?>